package com.ruoyi.exam.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import java.util.List;
import com.ruoyi.common.result.Result;

import com.ruoyi.exam.service.ISubjectService;
import com.ruoyi.exam.domain.Subject;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  学科表 前端控制器
 * </p>
 *
 * @author FSD
 * @since 2024-02-23
 */
@Api(tags = " 学科表")
@RestController
@RequestMapping("/exam/subject")
    public class SubjectController {
@Resource(name = "SubjectServiceImpl")
private ISubjectService subjectService;

/**
* 新增
*/
@PostMapping("/save")
@ApiOperation(value = "新增",notes = "新增")
@ApiImplicitParam(name = "subject" ,value = "subject实体类",dataTypeClass = String.class)
public Result insert(@RequestBody Subject subject) {
        return Result.ok(subjectService.save(subject));
        }

/**
* 修改
*/
@PostMapping("/update")
@ApiOperation(value = "修改",notes = "修改")
@ApiImplicitParam(name = "subject" ,value = "subject实体类",dataTypeClass = String.class)
public Result update(@RequestBody Subject subject) {
        return Result.ok(subjectService.updateById(subject));
        }

/**
* 根据id删除
*/
@PostMapping("/delete/{id}")
@ApiOperation(value = "根据id删除",notes = "根据id删除")
@ApiImplicitParam(name = "id" ,value = "id",dataTypeClass = Integer.class)
public Result delete(@PathVariable Integer id) {
        return Result.ok(subjectService.removeById(id));
        }

/**
* 批量删除
*/
@PostMapping("/del/batch")
public Result deleteBatch(@RequestBody List<Integer> ids) {
        return Result.ok(subjectService.removeByIds(ids));
        }

/**
* 查询全部
*/
@GetMapping("/getAll")
@ApiOperation(value = "查询全部",notes = "查询全部")
public Result findAll() {
        return Result.ok(subjectService.list());
        }

/**
* 根据id查询一个
*/
@GetMapping("getById/{id}")
@ApiOperation(value = "根据id查询一个",notes = "根据id查询一个")
@ApiImplicitParam(name = "id" ,value = "id",dataTypeClass = Integer.class)
public Result findOne(@PathVariable Integer id){
        return Result.ok(subjectService.getById(id));
        }

/**
* 分页模糊查询
*/
@GetMapping("/get/page")
@ApiOperation(value = "分页模糊查询",notes = "分页模糊查询")
public Result findPage(@RequestParam Integer pageNum,
@RequestParam Integer pageSize) {
        QueryWrapper<Subject> queryWrapper = new QueryWrapper<>();
        // 倒序查询
        queryWrapper.orderByDesc("id");
        return Result.ok(subjectService.page(new Page<>(pageNum, pageSize),queryWrapper));
        }
        }

